package com.oasystem.web.view;

import java.io.OutputStream;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

import com.oasystem.domain.ProfitReturnedRecord;
import com.oasystem.utils.DateUtils;

public class ProfitReturnedTodayExcelView extends AbstractExcelView {

	@Override
	protected void buildExcelDocument(Map<String, Object> map,
			HSSFWorkbook xls, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HSSFSheet sheet = xls.createSheet("test");
		HSSFRow row = sheet.createRow(0);
		row.createCell(0).setCellValue("银行卡号");
		sheet.setColumnWidth(0, 25*256);
		row.createCell(1).setCellValue("金额");
		sheet.setColumnWidth(1, 15*256);
		row.createCell(2).setCellValue("姓名");
		sheet.setColumnWidth(2, 10*256);
		List<ProfitReturnedRecord> list = (List<ProfitReturnedRecord>) map.get("profitReturnRecordToday");
		int size = list.size();
		String today = DateUtils.getTodayDateString();
		for (int i = 1; i <= size; i++) {
			HSSFRow row1 = sheet.createRow(i);
			ProfitReturnedRecord record = list.get(i-1);
			row1.createCell(0).setCellValue(record.getMemberCardNumber());
			row1.createCell(1).setCellValue(record.getTodayReturnAmount());
			row1.createCell(2).setCellValue(record.getName());
		}
		
		String fileName = "profitReturned.xls";// 设置下载时客户端Excel的名称
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-disposition", "attachment;filename="
				+ fileName);
		OutputStream ouputStream = response.getOutputStream();
		xls.write(ouputStream);
		ouputStream.flush();
		ouputStream.close();
	}

}
